package rs.dalao.syc.user.chat.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import rs.dalao.syc.common.pojo.authentication.CurrentPrincipal;
import rs.dalao.syc.common.response.JsonResult;
import rs.dalao.syc.user.chat.pojo.vo.*;
import rs.dalao.syc.user.chat.service.IChatService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/chat/")
public class ChatController {
    @Autowired
    private IChatService service;

    @GetMapping("consultDr/{depId}")
    public JsonResult selectConsultDr(@PathVariable Integer depId) {
        List<ConsultDrVO> consultDrs = service.selectConsultDr(depId);
        return JsonResult.ok(consultDrs);
    }

    @GetMapping("otherArticle/{depId}")
    public JsonResult selectOtherArticle(@PathVariable Integer depId) {
        List<OtherArticleVO> otherArticles = service.selectOtherArticle(depId);
        return JsonResult.ok(otherArticles);
    }

    @PostMapping("queryHistory")
    @ApiOperation("聊天记录查找")
    public JsonResult queryHistory(String doc_name,String user_name) {
        Map param = new HashMap();
        param.put("doc_name", doc_name);
        param.put("user_name", user_name);
        List<QueryChatVO> queryChatVOS = service.queryChat(param);
        return JsonResult.ok(queryChatVOS);
    }

    @GetMapping("getDep")
    @ApiOperation("聊天记录查找")
    public JsonResult getDep(@ApiIgnore @AuthenticationPrincipal CurrentPrincipal currentPrincipal){
        List<DoctorDepVO> dep = service.getDep(currentPrincipal.getId());
        return JsonResult.ok(dep);
    }

    @GetMapping("depList/{type}")
    @ApiOperation("聊天室科室目录一类")
    @ApiOperationSupport(order = 201)
    public JsonResult getDepList(@PathVariable Integer type) {
        log.debug("开始处理【查询疫苗list】的请求，参数：{}", type);
        List<DepartmentVO> getDepList = service.getDepList(type);
        return JsonResult.ok(getDepList);
    }

    @PostMapping("getAvatar/{userName}")
    @ApiOperation("获取双方avatar")
    @ApiOperationSupport(order = 202)
    public JsonResult getAvatar(@PathVariable String userName){
        List<AvatarVO> avatarVOS=service.getAvatar(userName);
        return JsonResult.ok(avatarVOS);
    }
}
